package com.fullstuck.service.impl;

import com.fullstuck.dao.impl.PigDaoimpl;
import com.fullstuck.service.PigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.sql.SQLOutput;


//等价<bean id="pid_service" class="com.fullstuck.service.impl.PigServiceimpl">
//@Component("pid_service")
//Scope 设置bean的Scope属性
@Service("pid_service")
@Scope("singleton")
public class PigServiceimpl implements PigService {



    //依赖注入
    //等价<property name="pig" ref="pig_dao"></property>
    // @Autowired 实现set
    //@Qualifier 注入信息
    @Autowired
    @Qualifier("pig_dao")
    private PigDaoimpl pig;

    //@Resource(name = "pig_dao") 等价于 @Autowired+@Qualifier("pig_dao")

//    @Resource(name = "pig_dao")
//    private PigDaoimpl pig;
   //读取 properties 的值并且注入
    @Value("${jdbc.driver}")
    private String driver;
    //注入普通的值
    @Value("猪叫猪八戒")
    private String pigName;
    //初始化前执行
    @PostConstruct
    public void begin(){
        System.out.println("pig 初始化");
    }
    //销毁时执行
    @PreDestroy
    public void end(){
        System.out.println("pig销毁");
    }

    //实现set方法
//    public void setPig(PigDaoimpl pig) {
//        this.pig = pig;
//    }

    public void dopig_eat() {

        System.out.println("猪要吃饭了");
        pig.eat();
        System.out.println("猪吃完饭了");
        System.out.println("输出注入的String类型数据："+pigName);
        System.out.println("输出Driver信息"+driver);

    }


    public void setPig(PigDaoimpl pig) {
    }
}
